package com.example.taiyang.guidepro0503.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.taiyang.guidepro0503.R;
import com.example.taiyang.guidepro0503.bean.WeatherInfo;
import com.example.taiyang.guidepro0503.listener.WeatherListener;
import com.example.taiyang.guidepro0503.mode.WeatherMode;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,WeatherListener{
    EditText editCityNumber;
    Button button_CH,button_51;
    TextView textCityName,textTemp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    void initView(){//初始化控件
        editCityNumber=(EditText)findViewById(R.id.edit_cityNumber);
        button_CH=(Button)findViewById(R.id.button_ch);
        button_51=(Button) findViewById(R.id.button_51);
        textCityName=(TextView)findViewById(R.id.text_cityName);
        textTemp=(TextView)findViewById(R.id.text_temp);

        button_CH.setOnClickListener(this);
        button_51.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
      switch (v.getId()){
          case R.id.button_ch:
              WeatherMode mode=new WeatherMode();
              mode.getWeather(editCityNumber.getText().toString(),this);
              break;

          case  R.id.button_51:
              ////////////
              break;


      }
    }

    @Override
    public void onResponse(WeatherInfo weatherInfo) {
        textCityName.setText(weatherInfo.getCity());
        textTemp.setText(weatherInfo.getTemp());

    }

    @Override
    public void onFailure(String msg) {
       textCityName.setText(msg);
    }
}
